<template>
	<view>
		<view class="cu-card case" :class="isCard?'no-card':''" v-for="item in tooklist" :key="item.id">
			<view class="cu-item shadow">
				<view class="image" style="height: 300px;" @tap="todetail(item.id)">
					<image :src="item.imgList[0]"
					 mode="aspectFill" style="height: 300px;"></image>
					<view class="cu-bar bg-shadeBottom"> <text class="text-cut">{{item.activityDesc}}</text></view>
				</view>
				<view class="cu-list menu-avatar">
					<view class="cu-item" @tap="todetail(item.id)">
						<view class="cu-avatar round lg" style="background-image:url(https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png);"></view>
						<view class="content flex-sub">
							<view class="text-grey">{{'名称:'+item.activityName}}</view>
							<view class="text-gray text-sm flex justify-between">
								{{item.activityDate}}
								<view class="text-gray text-sm">
									参与情况：{{item.tookNumber + '/' + item.limitNumber}}
								</view>
							</view>
						</view>
					</view>
					<view style="display: flex;flex-direction: row;">
						<button class="btn" style="width: 100%; color: #0081FF" plain='true' @tap="topinglun(item.activityName,item.id)">我要评价</button>
					</view>
				</view>
			</view>
		</view>
		<view v-if="this.tooklist.length == 0" style="width: 100%; padding: 20px 0 0 0;text-align: center;">
			<text style="font-size: 18px;">暂时还没有参与过的活动哟</text>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				name: '',
				Authorization:'',
				tooklist:[],
				isCard: false
			}
		},
		onLoad() {
			this.getCookies()
			this.gettook()
			uni.startPullDownRefresh();
		},
		onPullDownRefresh() {
			this.gettook()
		    setTimeout(function () {
		        uni.stopPullDownRefresh();
		    }, 1000);
		},
		methods: {
			topinglun(name,activityid) {
				uni.navigateTo({
					url: './pinglun?activityId='+activityid+'&activityName='+name+'&userId='+this.id+'&Authorization='+this.Authorization,
				    success: res => {}
				});
			},
			todetail(activityid) {
				let ismine = false
				uni.navigateTo({
					url: '../../activitydeatil/activitydeatil?activityid='+activityid+'&ismine='+ismine,
				    success: res => {}
				});
			},
			gettook() {
				let that = this
				uni.request({
				    url: 'http://101.37.15.60:8080/users/tookActivityList', 
				    header: {
				        'Authorization': "Bearer " + that.Authorization
				    },
				    success: (res) => {
				        if(res.data.message == 'SUCCESS') {
							that.tooklist = res.data.data
							for(let i = 0;i<res.data.data.length;i++){
							  let time = res.data.data[i].activityDate
							  let arrTime = []
							  arrTime = time.split(' ')
							  let newTime = arrTime[0]
							  this.tooklist[i].activityDate = newTime
							}
						}
				    }
				});
			},
			getCookies() {
			  if (document.cookie.length > 0) {
			    var arr = document.cookie.split("; "); //这里显示的格式需要切割一下自己可输出看下
			    for (var i = 0; i < arr.length; i++) {
			      var arr2 = arr[i].split("="); //再次切割
			      //判断查找相对应的值
			      if (arr2[0] == "name") {
			        this.name = arr2[1]; //保存到保存数据的地方
			      }else if(arr2[0] == "id") {
					  this.id = arr2[1]
				  }else if(arr2[0] == "Authorization") {
					  this.Authorization = arr2[1]
				  }
			    }
			  }
			},
		}
	}
</script>

<style scoped>
	.btn {
		border: #EEEEEE 1px solid;
		color: rgb(239, 109, 89);;
	}
</style>
